﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Size.ascx.cs" Inherits="Bussiness.View.BackEnd.User_Control.Size" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<ext:Window ID="pu_Size" runat="server" Icon="Group" Title="Tìm kiếm sản phẩm" Width="120" Height="220" Hidden="true" Layout="FormLayout" LabelAlign="Left"
            PaddingSummary="10px 10px 0 10px" IDMode="Static">
            <Items>
<ext:GridPanel ID="DSSize_Grid" IDMode="Static" runat="server" Height="170" AutoScroll="true"
                                    Region="Center">
                                    <Store>
                                        <ext:Store ID="DSSize_Store" runat="server" AutoDataBind="true" SkipIdForNewRecords="false">
                                            <Reader>
                                                <ext:JsonReader IDProperty="ID">
                                                    <Fields>
                                                        <ext:RecordField Name="ID" Type="String" Mapping="ID" />
                                                        <ext:RecordField Name="Size" Type="String" Mapping="Size" />
                                                        <ext:RecordField Name="Count" Type="String" Mapping="Count" />
                                                        
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <ColumnModel ID="ColumnModel2" runat="server" AutoDataBind="true">
                                        <Columns>
                                            
                                            <ext:Column ColumnID="ID" Header="Mã" DataIndex="ID" Hidden="true" />
                                            <ext:Column Header="Size" DataIndex="Size" AutoDataBind="true" Width="70"
                                                MenuDisabled="True" />
                                                <ext:Column Header="Số lượng" DataIndex="Count" AutoDataBind="true" Width="70"
                                                MenuDisabled="True" />
                                        </Columns>
                                    </ColumnModel    >                             
                                    <SelectionModel>
                                         <ext:CheckboxSelectionModel ID="CheckboxSelectionModel111"  runat="server" SingleSelect="true"/>
                                    </SelectionModel>
                                    <Listeners>
                                        <Command Handler="detail(command, record.data.Size)" />
                                    </Listeners>
                                    <Buttons>
                        <ext:Button runat="server" Text="Chọn" ID="Button61" Icon="Add">
                            <Listeners>
                <Click  Fn="Select1"/>
            </Listeners>
                        </ext:Button>
                        <ext:Button runat="server" Text="Đóng" ID="Button71" Icon="Cancel">
                             
                        </ext:Button>
                    </Buttons>
                                </ext:GridPanel>
                                
    </Items>
    </ext:Window>                            
                                <script language="javascript">
            function Select1() {
                var records = Ext.getCmp('DSSize_Grid').getSelectionModel().getSelected();
                var grid = Ext.getCmp('DS_SanPham_Grid');

                    var record1 = grid.getSelectionModel().getSelected();
                    record1.data['Size'] = records.data['Size'];
                    record1.data['FactSizeCount'] = records.data['Count'];
                    record1.data['ID_Size'] = records.data['ID'];

                    if (record1.data['Quantity'] > records.data['Count']) {
                        Ext.Msg.alert('Lỗi', 'Bạn chỉ có thể chọn tối đa ' + Number(record1.data['FactSizeCount']) + ' sản phẩm ' + record1.data['NameProduct']);
                        Ext.getCmp('pu_Size').setVisible(false);
                        record1.data['Quantity'] = " ";
                        Ext.getCmp('DS_SanPham_Grid').getView().refresh();
                        return false;
                    }
                    
                    
                    Ext.getCmp('DS_SanPham_Grid').getView().refresh();

                Ext.getCmp('pu_Size').setVisible(false);

            }
        </script>